<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="auto" v-show="showSearch">
            <el-form-item label="用户id">
                <el-input
                    v-model="queryParams.userid"
                    placeholder="请输入用户id"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="退款订单号">
                <el-input
                    v-model="queryParams.orderCode"
                    placeholder="请输入退款订单号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
            <el-form-item label="手机号">
                <el-input
                    v-model="queryParams.phone"
                    placeholder="请输入手机号"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item>
						<!-- <el-form-item label="所属运营商" prop="operatId">
							<el-select style="width: 200px;" v-model="queryParams.operatId" placeholder="请选择">
								<el-option
										v-for="item in operatorOptions"
										:key="item.id"
										:label="item.label"
										:value="item.id"
								></el-option>
							</el-select>
						</el-form-item> -->
            <!-- <el-form-item label="用户类型">
                <el-input
                    v-model="queryParams.user_type"
                    placeholder="请输入用户类型"
                    clearable
                    @keyup.enter="handleQuery"
                />
            </el-form-item> -->
            <el-form-item label="退款状态">
                <el-select  style="width: 200px;" v-model="queryParams.refundStatus"
                           clearable
                           placeholder="请选择">
                    <el-option
                        v-for="item in dict.type.refund_status_options"
                        :key="item.value"
                        :label="item.label"
                        :value="parseInt(item.value)"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="创建时间">
              <el-date-picker
                v-model="dateRange"
                type="datetimerange"
                range-separator="-"
                start-placeholder="开始日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="width:333px;"
                :default-time="['00:00:00','23:59:59']"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
            <el-form-item >
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="list">
            <el-table-column label="ID" align="center" prop="id"/>
            <el-table-column label="用户ID" align="center" prop="userid"/>
            <el-table-column label="退款订单号" align="center" prop="orderCode" :show-overflow-tooltip="true"/>
            <el-table-column label="申请退款金额" align="center" prop="needPrice" :formatter="(row) => {return '￥' + row.needPrice}"/>
            <el-table-column label="已退款金额" align="center" prop="alreadyPrice" :formatter="(row) => {return '￥' + row.alreadyPrice}"/>
            <el-table-column label="未退款金额" align="center" prop="notPrice" :formatter="(row) => {return '￥' + row.notPrice}"/>
            <el-table-column label="退款时间" align="center" prop="refundTime">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.refundTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="手机号" align="center" prop="phone"/>
            <!-- <el-table-column label="所属运营商" align="center" prop="operatorName"/> -->
            <el-table-column label="退款状态" align="center" prop="refundStatus">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.refund_status_options" :value="row.refundStatus" />
                </template>
            </el-table-column>
            <!-- <el-table-column label="支付类型" align="center" prop="payType">
                <template slot-scope="{row}">
                    <dict-tag :options="dict.type.refund_pay_type" :value="row.payType" />
                </template>
            </el-table-column> -->
            <!-- <el-table-column label="用户类型" align="center" prop="user_type"/> -->
            <el-table-column label="昵称" align="center" prop="nickName"/>
            <el-table-column label="头像地址" align="center">
                <template slot-scope="{row}">
                    <el-image :src="row.avatar" style="width: 40px;">
                        <template #error>
                            <div class="image-slot">
                                <el-icon><Picture /></el-icon>
                            </div>
                        </template>
                    </el-image>
                </template>
            </el-table-column>
            <el-table-column label="创建时间" align="center" prop="createTime">
                <template slot-scope="{row}">
                    <span>{{ parseTime(row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="操作" width="180" align="center" class-name="small-padding fixed-width">
                <template slot-scope="{row}">
                    <el-button
                       type="text"
                       @click="handleUpdate(row, 1)"
                       v-hasPermi="['system:refund:refund']"
                       v-if="row.refundStatus == '0'">确定退款
                    </el-button>
                    <el-button
                       type="text"
                       @click="handleUpdate(row, -1)"
                       v-hasPermi="['system:refund:reject']"
                       v-if="row.refundStatus == '0'">驳回提现
                    </el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />

    </div>
</template>

<script>
import * as api from "@/api/finance/refund";
import {
    getAllOperator,
} from "@/api/station/billing_rules";
export default {
  name: 'Refund',
  dicts: ['refund_pay_type','refund_status_options',],
  components: {  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      queryParams: {// 查询参数
        pageNum: 1,
        pageSize: 10,
      },
      // 总条数
      total: 0,
      list:[],//页面数据
      dateRange:[],
    };
  },
  mounted(){
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true;
      let queryParams = {...this.queryParams}
      if(!this.dateRange) this.dateRange = []
      if(this.dateRange.length) {
        queryParams.startTime = this.dateRange[0]
        queryParams.endTime = this.dateRange[1]
      }
      api.listEaCarUserRefund(queryParams).then(response => {
        this.list = response.rows || [];
        this.total = response.total || 0;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.queryParams = {// 查询参数
        pageNum: 1,
        pageSize: 10,
      }
      this.resetForm("queryRef");
      this.handleQuery();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(api.EXPORT_URL, {
          ...this.queryParams
      }, `recharge_${new Date().getTime()}.xlsx`);
    },
    handleUpdate(row, refund_status) {
        var tips;
        if (refund_status == 1) {
            tips = '确定退款？';
        } else if (refund_status == -1) {
            tips = '驳回提现？';
        }
        this.$modal.confirm(tips).then( ()=> {
            return api.refundAudit({id: row.id, type: refund_status});
        }).then(() => {
            this.getList();
            this.$modal.msgSuccess("操作成功");
        }).catch(() => {
        });
    },
  }
}
</script>
